package com.tgy.clickhouse.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.tgy.clickhouse.datasource.AIopsDynamicDatasource;
import lombok.Data;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/***
 * @ClassName: Mysql2Config
 * @Description: 第二个Mysql的配置，结合在一起的配置
 * @Auther: tanggy3
 * @Date: 14:11 2022/9/2
 * @version : V1.0
 */
@Data
@ConfigurationProperties(prefix = "datasource.mysql2")
@Component//交给Spring
public class Mysql2Config {
    private String userName;
    private String password;
    private String driverClassName;
    private String url;


    /**
     * 创建第二个mysql bean
     * @return
     */
    @Bean(name = AIopsDynamicDatasource.MYSQL_DATASOURCE_2)
    @Qualifier(AIopsDynamicDatasource.MYSQL_DATASOURCE_2)
    public DataSource mysqlDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        dataSource.setUrl(url);
        dataSource.setDriverClassName(driverClassName);
        return dataSource;
    }
}
